home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / pr42sdk / examples / projects / transit / fx-bwipe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-07  |  7.8 KB  |  275 lines

  1. //=============================================================================
  2. //
  3. // Fx-bwipe.c - Transition effect plug-in (Band Wipe).
  4. //
  5. // Part of the Adobe Premiere 4.2 Plug-in Developer's Toolkit.
  6. //
  7. // Copyright 1993-96, Adobe Systems Incorporated, all rights reserved worldwide.
  8. //
  9. // Written by Nick Schlott.
  10. //
  11. // 1.00        1/25/94        njs
  12. // 1.02        1/10/96        ba        Updated for Premiere 4.2 and MSVC++ 2.2 & 4.0.
  13. //
  14. //-----------------------------------------------------------------------------
  15.  
  16. #include <windows.h>
  17.  
  18. #include "Compat.h"
  19. #include "Premiere.h"
  20.  
  21.  
  22. #define kDefBands 7
  23.  
  24. HINSTANCE        resInst;    // reference to our DLL resources
  25. EffectHandle    myData=NULL;
  26.  
  27.  
  28. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
  29. {    
  30.     switch (dwReason)
  31.     {
  32.         case DLL_PROCESS_ATTACH:
  33.             resInst = hDLL;
  34.             break;
  35.  
  36.         case DLL_THREAD_ATTACH:
  37.             break;
  38.  
  39.         case DLL_THREAD_DETACH:
  40.             break;
  41.  
  42.         case DLL_PROCESS_DETACH:
  43.             break;
  44.     }
  45.     return(TRUE);
  46. }
  47.  
  48.  
  49. /*----------------------------------------------
  50.     Center a window relative to the screen
  51.     Useful for centering dialogs
  52. -----------------------------------------------*/
  53.  
  54. VOID FAR center_wnd_higher (HWND hwnd)
  55. {
  56.     RECT    crct, box;
  57.     int        phgt, pwid;
  58.     HWND    parent;
  59.  
  60.     if ((parent = GetParent(hwnd)))
  61.     {
  62.         GetClientRect(parent, &box);
  63.         pwid = box.right-box.left;
  64.         phgt = box.bottom-box.top;
  65.     }
  66.     else
  67.     {
  68.         pwid = GetSystemMetrics(SM_CXSCREEN);
  69.         phgt = GetSystemMetrics(SM_CYSCREEN);
  70.     }
  71.     
  72.     GetWindowRect(hwnd, &crct);
  73.     pwid = (pwid - (crct.right-crct.left)) / 2;
  74.     phgt = ((phgt - (crct.bottom-crct.top))*2)/6;
  75.     SetWindowPos(hwnd, NULL, pwid, phgt, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
  76. }
  77.  
  78.  
  79. //--------------------------------------------------------------------------
  80. // Proc for the filter param dialog
  81.  
  82. BOOL CALLBACK AskDlogProc (HWND wnd, UINT message, WPARAM wParam, LPARAM lParam)
  83. {
  84.     int        cmdid;
  85.     short    HMAX;
  86.     BOOL    trans;
  87.  
  88.     switch(message)
  89.     {
  90.     case WM_INITDIALOG:
  91.         myData = (EffectHandle)lParam;
  92.         if ((*myData)->specsHandle)
  93.         {
  94.             HMAX = (*((short**)(*myData)->specsHandle))[0];
  95.         }
  96.         else
  97.         {
  98.             HMAX = kDefBands;
  99.         }
  100.         SetDlgItemInt(wnd, 10, HMAX, 0);
  101.         SendDlgItemMessage(wnd, 10, EM_SETSEL, 0, MAKELONG(0,32767));
  102.         SendDlgItemMessage(wnd, 10, EM_LIMITTEXT, 2, 0);
  103.         SetFocus(GetDlgItem(wnd, 10));
  104.         center_wnd_higher(wnd);
  105.         return TRUE;
  106.  
  107.     case WM_CLOSE:
  108.         EndDialog(wnd, (short)lParam);
  109.         break;
  110.  
  111.     case WM_COMMAND:
  112.         cmdid = LOWORD(wParam);
  113.         switch (cmdid)
  114.         {
  115.         case IDOK:
  116.             HMAX = GetDlgItemInt(wnd, 10, &trans, 0);
  117.             if(HMAX <=2 || HMAX > 32) 
  118.             {
  119.                 MessageBeep(0);
  120.                 if(HMAX <=2)
  121.                     SetDlgItemInt(wnd, 10, 3, 0);
  122.                 else
  123.                     SetDlgItemInt(wnd, 10, 32, 0);
  124.                 SetFocus(GetDlgItem(wnd, 10));
  125.             }
  126.             else
  127.             {
  128.                 if (!(*myData)->specsHandle)
  129.                     (*myData)->specsHandle = NewHandle(sizeof(short));
  130.                 if ((*myData)->specsHandle)
  131.                 {
  132.                     (*((short**)(*myData)->specsHandle))[0] = HMAX;
  133.                 }
  134.                 SendMessage(wnd, WM_CLOSE, cmdid, 0);
  135.             }
  136.             return TRUE;
  137.  
  138.         case IDCANCEL:
  139.             SendMessage(wnd, WM_CLOSE, cmdid, 1);
  140.             return TRUE;
  141.         }
  142.         break;
  143.     }
  144.     return FALSE;
  145. }
  146.  
  147.  
  148.  
  149. //--------------------------------------------------------------------------
  150. void AddPolyPt (LPPOINT pts, short *cnt, int h, int v)
  151. {
  152.     pts[*cnt].x = h;
  153.     pts[*cnt].y = v;
  154.     *cnt = (*cnt) + 1;
  155. }
  156.  
  157.  
  158. //--------------------------------------------------------------------------
  159. int PRMEXPORT xEffect (short selector, EffectHandle theData)
  160. {
  161.     short            hpart, vpart, width, height, i;
  162.     short            hdiv, vdiv, dist, offset, thisoffset, off1, off2;
  163.     HRGN            rgn1, rgn2;
  164.     RECT            fullbox, partbox;
  165.     PPixHand        srcpix1, srcpix2, dstpix;
  166.     short            numbands;
  167.     POINT            pt1, pt2;
  168.     LPPOINT            pts;
  169.     short            numpts;
  170.     short            result = 0;
  171.  
  172.     switch(selector)
  173.     {
  174.     case esSetup:
  175.         myData = NULL;
  176.         result = DialogBoxParam(resInst, MAKEINTRESOURCE(1000),
  177.                         GetLastActivePopup(GetMainWnd()),
  178.                         (DLGPROC)AskDlogProc, (LPARAM)theData);
  179.         break;
  180.     case esExecute:
  181.         if ((*theData)->specsHandle) {
  182.             numbands = **((short**)(*theData)->specsHandle);
  183.         }
  184.         else numbands = kDefBands;
  185.  
  186.         srcpix1 = ((*theData)->source1);
  187.         srcpix2 = ((*theData)->source2);
  188.         dstpix  = ((*theData)->destination);
  189.  
  190.         hdiv = vdiv = 1;
  191.         if ((*theData)->sizeFlags & gvHalfH) vdiv = 2;
  192.         if ((*theData)->sizeFlags & (gvHalfV+gvFieldsEven+gvFieldsOdd)) hdiv = 2;
  193.         if ((hdiv == 2) && (vdiv == 2)) hdiv = vdiv = 1;
  194.             
  195.         fullbox = partbox = (*dstpix)->bounds;
  196.         width = (short)(fullbox.right-fullbox.left);
  197.         height = (short)(fullbox.bottom-fullbox.top);
  198.         hpart = (short)((long)(*theData)->part * width / (*theData)->total);
  199.         vpart = (short)((long)(*theData)->part * height / (*theData)->total);
  200.         dist = height/vdiv/2 + width/hdiv/2;
  201.         offset = (short)((*theData)->part * (long)dist / (*theData)->total);
  202.  
  203.         ((*theData)->bottleNecks->StretchBits)(*srcpix2, *dstpix, &fullbox, &fullbox, 0, NULL);
  204.  
  205.         pts = (LPPOINT)NewPtr(100);
  206.  
  207.         rgn1 = CreateRectRgnIndirect(&fullbox);
  208.         for (i=0; i<numbands; i++) 
  209.         {
  210.             partbox = fullbox;
  211.             numpts=0;
  212.             switch ((*theData)->arrowFlags) 
  213.             {
  214.             case bitUpperLeft+bitLowerRight:
  215.                 pt1.x = fullbox.left + width/2;
  216.                 pt1.y = fullbox.top - (short)(width*(long)vdiv/hdiv/2);
  217.                 pt2.x = fullbox.right + (short)(height*(long)hdiv/vdiv/2);
  218.                 pt2.y = fullbox.top + height/2;
  219.                 off1 = (short)(i * (long)dist / numbands);
  220.                 off2 = (short)((i+1) * (long)dist / numbands);
  221.                 thisoffset = (i&1) ? (dist-offset):-(dist-offset);
  222.                 AddPolyPt(pts, &numpts,pt1.x+(thisoffset-off1)*hdiv,pt1.y+(thisoffset+off1)*vdiv);
  223.                 AddPolyPt(pts, &numpts,pt1.x+(thisoffset-off2)*hdiv,pt1.y+(thisoffset+off2)*vdiv);
  224.                 AddPolyPt(pts, &numpts,pt2.x+(thisoffset-off2)*hdiv,pt2.y+(thisoffset+off2)*vdiv);
  225.                 AddPolyPt(pts, &numpts,pt2.x+(thisoffset-off1)*hdiv,pt2.y+(thisoffset+off1)*vdiv);
  226.                 AddPolyPt(pts, &numpts,pt1.x+(thisoffset-off1)*hdiv,pt1.y+(thisoffset+off1)*vdiv);
  227.                 rgn2 = CreatePolygonRgn(pts, numpts, ALTERNATE);
  228.                 CombineRgn(rgn1,rgn1,rgn2,RGN_DIFF);
  229.                 DeleteObject(rgn2);
  230.                 break;
  231.             case bitLowerLeft+bitUpperRight:
  232.                 pt1.x = fullbox.left - (short)(height*(long)hdiv/vdiv/2);
  233.                 pt1.y = fullbox.top + height/2;
  234.                 pt2.x = fullbox.left + width/2;
  235.                 pt2.y = fullbox.top - (short)(width*(long)vdiv/hdiv/2);
  236.                 off1 = (short)(i * (long)dist / numbands);
  237.                 off2 = (short)((i+1) * (long)dist / numbands);
  238.                 thisoffset = (i&1) ? (dist-offset):-(dist-offset);
  239.                 AddPolyPt(pts,&numpts,pt1.x+(off1-thisoffset)*hdiv,pt1.y+(off1+thisoffset)*vdiv);
  240.                 AddPolyPt(pts,&numpts,pt1.x+(off2-thisoffset)*hdiv,pt1.y+(off2+thisoffset)*vdiv);
  241.                 AddPolyPt(pts,&numpts,pt2.x+(off2-thisoffset)*hdiv,pt2.y+(off2+thisoffset)*vdiv);
  242.                 AddPolyPt(pts,&numpts,pt2.x+(off1-thisoffset)*hdiv,pt2.y+(off1+thisoffset)*vdiv);
  243.                 AddPolyPt(pts,&numpts,pt1.x+(off1-thisoffset)*hdiv,pt1.y+(off1+thisoffset)*vdiv);
  244.                 rgn2 = CreatePolygonRgn(pts, numpts, ALTERNATE);
  245.                 CombineRgn(rgn1,rgn1,rgn2,RGN_DIFF);
  246.                 DeleteObject(rgn2);
  247.                 break;
  248.             case bitTop+bitBottom:
  249.                 partbox.left = (short)((long)width * i / numbands);
  250.                 partbox.right = (short)((long)width * (i+1) / numbands);
  251.                 if (i&1) partbox.bottom = partbox.top + vpart;
  252.                 else partbox.top = partbox.bottom - vpart;
  253.                 rgn2 = CreateRectRgnIndirect(&partbox);
  254.                 CombineRgn(rgn1,rgn1,rgn2,RGN_DIFF);
  255.                 DeleteObject(rgn2);
  256.                 break;
  257.             default:
  258.                 partbox.top = (short)((long)height * i / numbands);
  259.                 partbox.bottom = (short)((long)height * (i+1) / numbands);
  260.                 if (i&1) partbox.right = partbox.left + hpart;
  261.                 else partbox.left = partbox.right - hpart;
  262.                 rgn2 = CreateRectRgnIndirect(&partbox);
  263.                 CombineRgn(rgn1,rgn1,rgn2,RGN_DIFF);
  264.                 DeleteObject(rgn2);
  265.                 break;
  266.             }
  267.         }
  268.         ((*theData)->bottleNecks->StretchBits)(*srcpix1, *dstpix, &fullbox, &fullbox, 0, rgn1);
  269.         DeleteObject(rgn1);
  270.         DisposPtr((Ptr)pts);
  271.         break;
  272.     }
  273.     return result;
  274. }
  275.